package com.bang.daybreak.common.util;


import com.bang.daybreak.common.framework.model.TreeNode;

import java.util.List;
import java.util.Objects;


/**
 * 树工具类
 *
 * @author : wdj
 * @since : 2019/4/28 0028 下午 12:02
 * @version 1.0
 */
public abstract class TreeUtils {

    /**
     * 递归查找子节点
     *
     * @param treeNodes
     * @return
     */
    public static <T extends TreeNode> T findChildren(T treeNode, List<T> treeNodes) {
        treeNodes.stream().filter(e -> Objects.equals(treeNode.getId(), e.getParentId())).forEach(e -> treeNode.getChildren().add(findChildren(e, treeNodes)));
        return treeNode;
    }

    /**
     * 递归获取父节点
     *
     * @param deleteFlowNode
     * @param deleteFlowNodes
     * @param <T>
     * @return
     */
 /*   public static <T extends ApplyFlowNode> T findParent(T deleteFlowNode, List<T> deleteFlowNodes) {
        deleteFlowNodes.stream().filter(e -> Objects.equals(deleteFlowNode.getPPDeptId(), e.getPDeptId())).forEach(e -> deleteFlowNode.getParent().add(findParent(e, deleteFlowNodes)));
        return deleteFlowNode;
    }*/

}
